package com.app.micaihu.view.home.exclusive.header

import android.annotation.SuppressLint
import android.content.Intent
import androidx.recyclerview.widget.RecyclerView
import com.app.base.BaseHeaderView
import com.app.micaihu.R
import com.app.micaihu.base.BaseOldActivity
import com.app.micaihu.bean.news.VideoChannel
import com.app.micaihu.configure.Config
import com.app.micaihu.view.home.exclusive.adapter.ExclusiveListHeaderAdapter
import com.app.micaihu.view.main.view.WrapContentLinearLayoutManager
import com.app.micaihu.view.newsdetail.VideoShowActivity
import com.blankj.utilcode.util.ActivityUtils
import kotlinx.android.synthetic.main.exclusive_list_header.view.*

@SuppressLint("ViewConstructor")
class ExclusiveHeader : BaseHeaderView(context = ActivityUtils.getTopActivity()) {

    override fun getLayoutId() = R.layout.exclusive_list_header

    private val exclusiveListAdapter by lazy {
        val exclusiveListAdapter = ExclusiveListHeaderAdapter()
        val manager = WrapContentLinearLayoutManager(context)
        manager.orientation = RecyclerView.HORIZONTAL
        rvHeader.layoutManager = manager
        rvHeader.adapter = exclusiveListAdapter
        exclusiveListAdapter
    }

    override fun setData() {

    }

    override fun addListeners() {
        exclusiveListAdapter.setOnItemClickListener { adapter, view, position ->
            val item = exclusiveListAdapter.getItem(position)
            val intent = Intent(context, VideoShowActivity::class.java)
            intent.putExtra(Config.Extra.PARAMETER1, item.id)
            ActivityUtils.startActivity(intent)
        }
    }

    fun setListData(list: List<VideoChannel>) {
        exclusiveListAdapter.setNewInstance(list.toMutableList())
    }
}